package com.jt.controller;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }
    @RequestMapping("/findUserById")
    public User findUserById(Integer id){
        return userService.findUserById(id);
    }
    @RequestMapping("/findUserByAS")
    private List<User> findUserByAS(User user){
        return userService.findUserByAS(user);
    }
    @PutMapping("/upDateById/{id}/{name}/{age}/{sex}")
    private String upDateById(User user){
        userService.upDateById(user);
        return "修改成功";
    }

    /**
     * 模糊查询 查询name中包含 "乔"的用户.
     * http://localhost:8090/findUserByLike?name=乔 返回list集合
     */
    @RequestMapping("/findUserByLike")
    public List<User> findUserByLike(String name){
        return userService.findUserByLike(name);
    }
    /**
     * 批量查询 查询id=1,3,5,7的数据
     * http://localhost:8090/findUserByIds?ids=1,3,5,7 返回list集合
     */
    @RequestMapping("/findUserByIds")
    public List<User> findUserByIds(Integer[] ids){
        return userService.findUserByIds(ids);
    }
    /**
     * 实现用户新增
     * http://localhost:8090/saveUser/悟空/8000/男 返回成功的提示即可
     */
    @RequestMapping("/saveUser/{name}/{age}/{sex}")
    public String saveUser(User user){
        userService.saveUser(user);
        System.out.println(user.getName());
        return "添加成功！";
    }
}
